// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manunal/en/scripting/life-cycle-callbacks.html

let { shopData, player, time, adPosition, achieveProcess, times  } = require("../shop/gameData");
const { show, msg } = require("./alert");

cc.Class({
    extends: cc.Component,

    properties: {
       
    },
    restart(){
        
        // cc.log(shopData)
        show('未来机器','请重启游戏，即将退出游戏',(res) => {
            if(res) {
                cc.sys.localStorage.removeItem("shopList");
                cc.sys.localStorage.removeItem("player");
                cc.sys.localStorage.removeItem("time");
                cc.sys.localStorage.removeItem("adPosition");
                cc.sys.localStorage.removeItem("shopName");
                cc.sys.localStorage.removeItem("mode");
                cc.sys.localStorage.removeItem("achieveProcess");
                cc.game.end();
            }
        });
        // cc.director.loadScene("main");
    },
    save(){
        console.log(shopData);
        cc.sys.localStorage.setItem('shopList', JSON.stringify(shopData));
        cc.sys.localStorage.setItem('player', JSON.stringify(player));
        cc.sys.localStorage.setItem('time', JSON.stringify(time));
        cc.sys.localStorage.setItem('adPosition', JSON.stringify(adPosition));
        cc.sys.localStorage.setItem('achieveProcess', JSON.stringify(achieveProcess));
        cc.sys.localStorage.setItem('times', JSON.stringify(times));
        cc.log(JSON.parse(cc.sys.localStorage.getItem('shopList')));
        show('未来机器','保存成功');
    },
    load(){
        show('未来机器','请重启游戏，即将退出游戏',(res) => {
            if(res) {
                cc.game.end();
            }
        });
    },
    changeMusic() {
        cc.find("Audio").getComponent("audio").playBgMusic();
        msg('音乐开启');

    },
    stopMusic() {
        cc.find("Audio").getComponent("audio").stopBgMusic();
       msg('音乐关闭');

    }
    // update (dt) {},
});
